/**
 * Project Name:mauto-web
 * File Name:TcAction.java
 * Package Name:com.inftech.mauto.jy.web
 * Date:2017年6月29日上午10:50:53
 * Copyright (c) 2017, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.jy.web;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.inftech.mauto.common.utils.CommonUtils;
import com.inftech.mauto.jy.service.JyItemTcService;
import com.mingsoft.base.action.BaseAction;

import net.mingsoft.basic.util.BasicUtil;
import net.sf.json.JSONObject;

/**
 * ClassName:TcAction <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Date: 2017年6月29日 上午10:50:53 <br/>
 * 
 * @author Administrator
 * @version
 * @since JDK 1.7
 */
@Controller
@RequestMapping("/${managerPath}/tc")
public class TcAction extends BaseAction {
	@Resource(name = "jyItemTcServiceImpl")
	private JyItemTcService jyItemTcServiceImpl;

	@RequestMapping("/tcList.do")
	public String tcList(HttpServletRequest request, HttpServletResponse response, String tcName) {
		BasicUtil.startPage();
		List<Map<String, Object>> tcList = jyItemTcServiceImpl.getTcList(tcName);
		request.setAttribute("tcList", tcList);
		BasicUtil.endPage(tcList);
		request.setAttribute("pageNo",
				CommonUtils.isBlank(request.getParameter("pageNo")) ? 1 : request.getParameter("pageNo"));
		return "/WEB-INF/manager/mauto/jy/tc";
	}
	
	@RequestMapping(value="/save.do",produces="application/jso;charset=utf-8")
	@ResponseBody
	public String save(HttpServletRequest request, HttpServletResponse response) {
		
		
		return null;
	}
	
	
	/**
	 * 
	 * allDelete:(删除套餐). <br/>
	 *
	 * @author Administrator
	 * @param request
	 * @param response
	 * @param tcName
	 * @return
	 * @since JDK 1.7
	 */
	@RequestMapping(value="/allDelete.do",produces="application/jso;charset=utf-8")
	@ResponseBody
	public String allDelete(HttpServletRequest request, HttpServletResponse response, String tcName) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Enumeration<String> enumeration = request.getParameterNames();
			String value = "";
			String name = "";
			List<String> list = new ArrayList<String>();
			while (enumeration.hasMoreElements()) {
				name = enumeration.nextElement();
				value = request.getParameter(name);
				list.add(value);
			}
			int row = jyItemTcServiceImpl.updateTc(list);
			if (row == 0) {
				map.put("resMsg", "删除失败！");
				map.put("flag", "1");
			} else {
				map.put("resMsg", "删除成功！");
				map.put("flag", "0");
			}
		} catch (Exception e) {
			map.put("resMsg", "删除失败！");
			map.put("flag", "1");
		}
		return JSONObject.fromObject(map).toString();
	}
	
	
}
